package com.guigu.limeng.controller;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.guigu.aop.OpLog;
import com.guigu.limeng.pojo.Mdesignprocedure;
import com.guigu.limeng.pojo.Mdesignproceduredetails;
import com.guigu.limeng.service.MdesignprocedureService;
import com.guigu.limeng.service.MdesignproceduredetailsService;
import com.guigu.tankai.service.DfileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("Mdesignproceduredetails.do")
public class MdesignproceduredetailsController {
    @Autowired
    MdesignproceduredetailsService mdesignproceduredetailsService;
    @Autowired
    MdesignprocedureService mdesignprocedureService;
    @Autowired
    DfileService dfileService;


    //添加
    @RequestMapping("/AddMdesignproceduredetails")
    @ResponseBody
    public String AddMdesignprocedure(String lists) {
        List<Mdesignproceduredetails> list = new Gson().fromJson(lists, new TypeToken<List<Mdesignproceduredetails>>() {
        }.getType());
        for (Mdesignproceduredetails m : list) {
            mdesignproceduredetailsService.AddMdeMingXi(m);
        }
        return "/li_meng/mApplyAdd(2).html";
    }

    //查询
    @RequestMapping("/ChaById")
    @ResponseBody
    public List<Mdesignproceduredetails> ChaById(Integer id) {
        return mdesignproceduredetailsService.ChaById(id);
    }

    //根据序号删除工序
    @RequestMapping("/delById")
    @ResponseBody
    public int delById(int id) {
        return mdesignproceduredetailsService.delById(id);
    }

    //修改工序
    @RequestMapping("/updateByMingXi")
    @OpLog(opModule = "生产管理",operType = "产品生产工序设计单变更",operDesc = "此方法用于产品生产工序设计单变更")
    public String updateByMingXi(String mdesignprocedure, String MDList) {
        // 修改 产品生产工序
        Mdesignprocedure md = new Gson().fromJson(mdesignprocedure,Mdesignprocedure.class);
        mdesignprocedureService.limengUpdate(md);
        // 修改 产品生产工序明细
        List<Mdesignproceduredetails> list = new Gson().fromJson(MDList, new TypeToken<List<Mdesignproceduredetails>>() {
        }.getType());
        for (Mdesignproceduredetails m : list) {
            mdesignproceduredetailsService.updateByMingXi(m);
        }
        return "/li_meng/SheJiDanBianGeng.html";
    }
}
